<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--卡片 -->
    <el-card>
      <!--  -->
      <el-input v-model="query" style="width: 400px;" placeholder="请输入内容" class="input-with-select">
        <!-- 具名插槽  -->
        <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
      </el-input>
      <!-- 表格 -->
      <el-table border stripe :data="tableData">
        <el-table-column type="index" label="序号" width="80">
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格">
        </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <div>
              <el-button size="mini" type="primary" icon="el-icon-edit" @click="dialogVisibleAddress = true"></el-button>
              <el-button size="mini" type="success" icon="el-icon-location" @click="showKuaiDi"></el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 @size-change="handleSizeChange" @current-change="handleCurrentChange" -->
      <el-pagination :current-page="pagenum" :page-sizes="[10, 20, 30, 40]" :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-card>
    <!-- dialogVisible控制对话框的显示 -->
    <el-dialog title="物流进度" :visible.sync="dialogVisible" width="50%">
      <!-- 时间线 -->
      <el-timeline :reverse="reverse">
        <el-timeline-item v-for="(activity, index) in activities" :key="index" :timestamp="activity.time">
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="修改地址" :visible.sync="dialogVisibleAddress" width="50%">
      <el-cascader :options="options" :props="{ expandTrigger: 'hover' }"></el-cascader>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
// axios二次封装的数据
import request from '@/utils/request'
import option from '@/assets/city_data2017_element.js'
export default {
  data () {
    return {
      query: '',
      pagenum: 1,
      pagesize: 10,
      total: 0,
      tableData: [],
      // 物流进度对话框是否显示
      dialogVisible: false,
      // 正序还是倒叙排列
      reverse: true,
      // 时间线数据
      activities: [{
        time: '2018-05-10 09:39:00',
        ftime: '2018-05-10 09:39:00',
        context: '已签收,感谢使用顺丰,期待再次为您服务',
        location: ''
      },
      {
        time: '2018-05-10 08:23:00',
        ftime: '2018-05-10 08:23:00',
        context: '[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件',
        location: ''
      },
      {
        time: '2018-05-10 07:32:00',
        ftime: '2018-05-10 07:32:00',
        context: '快件到达 [北京海淀育新小区营业点]',
        location: ''
      },
      {
        time: '2018-05-10 02:03:00',
        ftime: '2018-05-10 02:03:00',
        context: '快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]',
        location: ''
      },
      {
        time: '2018-05-09 23:05:00',
        ftime: '2018-05-09 23:05:00',
        context: '快件到达 [北京顺义集散中心]',
        location: ''
      },
      {
        time: '2018-05-09 21:21:00',
        ftime: '2018-05-09 21:21:00',
        context: '快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]',
        location: ''
      },
      {
        time: '2018-05-09 13:07:00',
        ftime: '2018-05-09 13:07:00',
        context: '顺丰速运 已收取快件',
        location: ''
      },
      {
        time: '2018-05-09 12:25:03',
        ftime: '2018-05-09 12:25:03',
        context: '卖家发货',
        location: ''
      },
      {
        time: '2018-05-09 12:22:24',
        ftime: '2018-05-09 12:22:24',
        context: '您的订单将由HLA（北京海淀区清河中街店）门店安排发货。',
        location: ''
      },
      {
        time: '2018-05-08 21:36:04',
        ftime: '2018-05-08 21:36:04',
        context: '商品已经下单',
        location: ''
      }],
      dialogVisibleAddress: false,
      // 数据
      options: option
    }
  },
  mounted () {
    this.getOrdersList()
  },
  methods: {
    async getOrdersList () {
      const { data: { data, meta } } = await request({
        url: 'orders',
        method: 'GET',
        params: {
          query: this.query,
          pagenum: this.pagenum,
          pagesize: this.pagesize
        }
      })
      if (meta.status !== 200) {
        return this.$message.error('获取数据失败')
      }
      this.tableData = data.goods
      this.total = data.total
    },
    search () {
      this.pagenum = 1
      this.getOrdersList()
    },
    showKuaiDi () {
      this.dialogVisible = true
    }
  }
}
</script>

<style lang="less" scoped>
.el-timeline {
  margin-left: 40px;
}
</style>
